from django.test import TestCase


class TestDataQuery(TestCase):
    def __init__(self, methodName: str = "runTest") -> None:
        super().__init__(methodName)

    def test_log(self):
        r"""
        http://123.249.88.244:8888/log?node=minikube&start_time=1716739200&end_time=1716739260
        """
        url = "/log"
        query = {
            "node": "minikube",
            "start_time": 1716739200,
            "end_time": 1716739260,
        }

        response = self.client.get(url, data=query)
        self.assertEqual(200, response.status_code)

    def test_log_extract(self):
        url = "/logextract"
        query = {
            "start_time": 1716739200,
            "end_time": 1716739260,
        }

        response = self.client.get(url, data=query)
        self.assertEqual(200, response.status_code)

    def test_lognum(self):
        url = "/lognum"
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)

    def test_metric(self):
        url = "/metric"
        query = {
            "pod": "checkoutservice",
            "metric_name": "container_cpu_system_seconds_total",
            "start_time": 1716808800,
            "end_time": 1716809700,
        }
        # no error
        response = self.client.get(url, data=query)
        self.assertEqual(200, response.status_code)
        # error
        query["start_time"] = 1716809710
        response = self.client.get(url, data=query)
        self.assertEqual(500, response.status_code)

    def test_metric_export(self):
        url = "/metricexport"
        query = {
            "start_time": 1716739200,
            "end_time": 1716739260,
        }

        response = self.client.get(url, data=query)
        self.assertEqual(200, response.status_code)

    def test_metric_name(self):
        url = "/metricname"
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)

    def test_trace(self):
        url = "/trace"
        query = {
            "start_time": 1716739200,
            "end_time": 1716739260,
        }

        response = self.client.get(url, data=query)
        self.assertEqual(200, response.status_code)

    def test_trace_id(self):
        url = "/traceid"
        query = {
            "trace_id": "8b00fa7e43c7d3296f8563bd1c0ce6e8"
        }
        response = self.client.get(url, data=query)
        self.assertEqual(200, response.status_code)


    def test_trace_extract(self):
        url = "/traceextract"
        query = {
            "start_time": 1716739200,
            "end_time": 1716739260,
        }

        response = self.client.get(url, data=query)
        self.assertEqual(200, response.status_code)
